
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/qubit.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:46 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Qubit &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="qubit.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="Shor’s Algorithm" href="shor.html" />
    <link rel="prev" title="QFT" href="qft.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="shor.html" title="Shor’s Algorithm"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="qft.html" title="QFT"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Qubit</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.physics.quantum.qubit">
<span id="qubit"></span><h1>Qubit<a class="headerlink" href="#module-sympy.physics.quantum.qubit" title="Permalink to this headline">¶</a></h1>
<p>Qubits for quantum computing.</p>
<p>Todo:
* Finish implementing measurement logic. This should include POVM.
* Update docstrings.
* Update tests.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.IntQubit">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">IntQubit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L342-L418"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.IntQubit" title="Permalink to this definition">¶</a></dt>
<dd><p>A qubit ket that store integers as binary numbers in qubit values.</p>
<p>The differences between this class and <code class="docutils literal notranslate"><span class="pre">Qubit</span></code> are:</p>
<ul class="simple">
<li><p>The form of the constructor.</p></li>
<li><p>The qubit values are printed as their corresponding integer, rather
than the raw qubit values. The internal storage format of the qubit
values in the same as <code class="docutils literal notranslate"><span class="pre">Qubit</span></code>.</p></li>
</ul>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> : int, tuple</p>
<blockquote>
<div><p>If a single argument, the integer we want to represent in the qubit
values. This integer will be represented using the fewest possible
number of qubits.
If a pair of integers and the second value is more than one, the first
integer gives the integer to represent in binary form and the second
integer gives the number of qubits to use.
List of zeros and ones is also accepted to generate qubit by bit pattern.</p>
</div></blockquote>
<p><strong>nqubits</strong> : int</p>
<blockquote>
<div><p>The integer that represents the number of qubits.
This number should be passed with keyword <code class="docutils literal notranslate"><span class="pre">nqubits=N</span></code>.
You can use this in order to avoid ambiguity of Qubit-style tuple of bits.
Please see the example below for more details.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Create a qubit for the integer 5:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">IntQubit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">Qubit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">IntQubit</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span>
<span class="go">|5&gt;</span>
</pre></div>
</div>
<p>We can also create an <code class="docutils literal notranslate"><span class="pre">IntQubit</span></code> by passing a <code class="docutils literal notranslate"><span class="pre">Qubit</span></code> instance.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">IntQubit</span><span class="p">(</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;101&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span>
<span class="go">|5&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">as_int</span><span class="p">()</span>
<span class="go">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">nqubits</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">qubit_values</span>
<span class="go">(1, 0, 1)</span>
</pre></div>
</div>
<p>We can go back to the regular qubit form.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Qubit</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">|101&gt;</span>
</pre></div>
</div>
<p>Please note that <code class="docutils literal notranslate"><span class="pre">IntQubit</span></code> also accepts a <code class="docutils literal notranslate"><span class="pre">Qubit</span></code>-style list of bits.
So, the code below yields qubits 3, not a single bit <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">IntQubit</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">|3&gt;</span>
</pre></div>
</div>
<p>To avoid ambiguity, use <code class="docutils literal notranslate"><span class="pre">nqubits</span></code> parameter.
Use of this keyword is recommended especially when you provide the values by variables.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">IntQubit</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">nqubits</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">|1&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">IntQubit</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">nqubits</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">|1&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.IntQubitBra">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">IntQubitBra</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L420-L425"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.IntQubitBra" title="Permalink to this definition">¶</a></dt>
<dd><p>A qubit bra that store integers as binary numbers in qubit values.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.Qubit">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">Qubit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L122-L254"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.Qubit" title="Permalink to this definition">¶</a></dt>
<dd><p>A multi-qubit ket in the computational (z) basis.</p>
<p>We use the normal convention that the least significant qubit is on the
right, so <code class="docutils literal notranslate"><span class="pre">|00001&gt;</span></code> has a 1 in the least significant qubit.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> : list, str</p>
<blockquote>
<div><p>The qubit values as a list of ints ([0,0,0,1,1,]) or a string (‘011’).</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Create a qubit in a couple of different ways and look at their attributes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">Qubit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Qubit</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="go">|000&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;0101&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span>
<span class="go">|0101&gt;</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">nqubits</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">dimension</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">qubit_values</span>
<span class="go">(0, 1, 0, 1)</span>
</pre></div>
</div>
<p>We can flip the value of an individual qubit:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">flip</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">|0111&gt;</span>
</pre></div>
</div>
<p>We can take the dagger of a Qubit to get a bra:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.dagger</span> <span class="kn">import</span> <span class="n">Dagger</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dagger</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">&lt;0101|</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">Dagger</span><span class="p">(</span><span class="n">q</span><span class="p">))</span>
<span class="go">&lt;class &#39;sympy.physics.quantum.qubit.QubitBra&#39;&gt;</span>
</pre></div>
</div>
<p>Inner products work as expected:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span> <span class="o">=</span> <span class="n">Dagger</span><span class="p">(</span><span class="n">q</span><span class="p">)</span><span class="o">*</span><span class="n">q</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span>
<span class="go">&lt;0101|0101&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ip</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">1</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.QubitBra">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">QubitBra</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L257-L277"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.QubitBra" title="Permalink to this definition">¶</a></dt>
<dd><p>A multi-qubit bra in the computational (z) basis.</p>
<p>We use the normal convention that the least significant qubit is on the
right, so <code class="docutils literal notranslate"><span class="pre">|00001&gt;</span></code> has a 1 in the least significant qubit.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>values</strong> : list, str</p>
<blockquote>
<div><p>The qubit values as a list of ints ([0,0,0,1,1,]) or a string (‘011’).</p>
</div></blockquote>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="#sympy.physics.quantum.qubit.Qubit" title="sympy.physics.quantum.qubit.Qubit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Qubit</span></code></a></dt><dd><p>Examples using qubits</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.matrix_to_density">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">matrix_to_density</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mat</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L503-L516"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.matrix_to_density" title="Permalink to this definition">¶</a></dt>
<dd><p>Works by finding the eigenvectors and eigenvalues of the matrix.
We know we can decompose rho by doing:
sum(EigenVal*|Eigenvect&gt;&lt;Eigenvect|)</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.matrix_to_qubit">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">matrix_to_qubit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">matrix</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L433-L500"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.matrix_to_qubit" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert from the matrix repr. to a sum of Qubit objects.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>matrix</strong> : Matrix, numpy.matrix, scipy.sparse</p>
<blockquote>
<div><p>The matrix to build the Qubit representation of. This works with
sympy matrices, numpy matrices and scipy.sparse sparse matrices.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Represent a state and then go back to its qubit form:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">matrix_to_qubit</span><span class="p">,</span> <span class="n">Qubit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.represent</span> <span class="kn">import</span> <span class="n">represent</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;01&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">matrix_to_qubit</span><span class="p">(</span><span class="n">represent</span><span class="p">(</span><span class="n">q</span><span class="p">))</span>
<span class="go">|01&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.measure_all">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">measure_all</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">normalize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L533-L586"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.measure_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform an ensemble measurement of all qubits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>qubit</strong> : Qubit, Add</p>
<blockquote>
<div><p>The qubit to measure. This can be any Qubit or a linear combination
of them.</p>
</div></blockquote>
<p><strong>format</strong> : str</p>
<blockquote>
<div><p>The format of the intermediate matrices to use. Possible values are
(‘sympy’,’numpy’,’scipy.sparse’). Currently only ‘sympy’ is
implemented.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>result</strong> : list</p>
<blockquote>
<div><p>A list that consists of primitive states and their probabilities.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">Qubit</span><span class="p">,</span> <span class="n">measure_all</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.gate</span> <span class="kn">import</span> <span class="n">H</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qapply</span> <span class="kn">import</span> <span class="n">qapply</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">H</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">*</span><span class="n">H</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;00&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span>
<span class="go">H(0)*H(1)*|00&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">qapply</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">measure_all</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">[(|00&gt;, 1/4), (|01&gt;, 1/4), (|10&gt;, 1/4), (|11&gt;, 1/4)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.measure_all_oneshot">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">measure_all_oneshot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L763-L804"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.measure_all_oneshot" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a oneshot ensemble measurement on all qubits.</p>
<p>A oneshot measurement is equivalent to performing a measurement on a
quantum system. This type of measurement does not return the probabilities
like an ensemble measurement does, but rather returns <em>one</em> of the
possible resulting states. The exact state that is returned is determined
by picking a state randomly according to the ensemble probabilities.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>qubits</strong> : Qubit</p>
<blockquote>
<div><p>The qubit to measure.  This can be any Qubit or a linear combination
of them.</p>
</div></blockquote>
<p><strong>format</strong> : str</p>
<blockquote>
<div><p>The format of the intermediate matrices to use. Possible values are
(‘sympy’,’numpy’,’scipy.sparse’). Currently only ‘sympy’ is
implemented.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>result</strong> : Qubit</p>
<blockquote>
<div><p>The qubit that the system collapsed to upon measurement.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.measure_partial">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">measure_partial</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bits</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">normalize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L589-L661"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.measure_partial" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a partial ensemble measure on the specified qubits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>qubits</strong> : Qubit</p>
<blockquote>
<div><p>The qubit to measure.  This can be any Qubit or a linear combination
of them.</p>
</div></blockquote>
<p><strong>bits</strong> : tuple</p>
<blockquote>
<div><p>The qubits to measure.</p>
</div></blockquote>
<p><strong>format</strong> : str</p>
<blockquote>
<div><p>The format of the intermediate matrices to use. Possible values are
(‘sympy’,’numpy’,’scipy.sparse’). Currently only ‘sympy’ is
implemented.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>result</strong> : list</p>
<blockquote>
<div><p>A list that consists of primitive states and their probabilities.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qubit</span> <span class="kn">import</span> <span class="n">Qubit</span><span class="p">,</span> <span class="n">measure_partial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.gate</span> <span class="kn">import</span> <span class="n">H</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.qapply</span> <span class="kn">import</span> <span class="n">qapply</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">H</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">*</span><span class="n">H</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">Qubit</span><span class="p">(</span><span class="s1">&#39;00&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span>
<span class="go">H(0)*H(1)*|00&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">qapply</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">measure_partial</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,))</span>
<span class="go">[(sqrt(2)*|00&gt;/2 + sqrt(2)*|10&gt;/2, 1/2), (sqrt(2)*|01&gt;/2 + sqrt(2)*|11&gt;/2, 1/2)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.measure_partial_oneshot">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">measure_partial_oneshot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bits</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L664-L709"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.measure_partial_oneshot" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a partial oneshot measurement on the specified qubits.</p>
<p>A oneshot measurement is equivalent to performing a measurement on a
quantum system. This type of measurement does not return the probabilities
like an ensemble measurement does, but rather returns <em>one</em> of the
possible resulting states. The exact state that is returned is determined
by picking a state randomly according to the ensemble probabilities.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>qubits</strong> : Qubit</p>
<blockquote>
<div><p>The qubit to measure.  This can be any Qubit or a linear combination
of them.</p>
</div></blockquote>
<p><strong>bits</strong> : tuple</p>
<blockquote>
<div><p>The qubits to measure.</p>
</div></blockquote>
<p><strong>format</strong> : str</p>
<blockquote>
<div><p>The format of the intermediate matrices to use. Possible values are
(‘sympy’,’numpy’,’scipy.sparse’). Currently only ‘sympy’ is
implemented.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>result</strong> : Qubit</p>
<blockquote>
<div><p>The qubit that the system collapsed to upon measurement.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.qubit.qubit_to_matrix">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.qubit.</span></span><span class="sig-name descname"><span class="pre">qubit_to_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'sympy'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/qubit.py#L519-L525"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.qubit.qubit_to_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an Add/Mul of Qubit objects into it’s matrix representation</p>
<p>This function is the inverse of <code class="docutils literal notranslate"><span class="pre">matrix_to_qubit</span></code> and is a shorthand
for <code class="docutils literal notranslate"><span class="pre">represent(qubit)</span></code>.</p>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="qft.html"
                        title="previous chapter">QFT</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="shor.html"
                        title="next chapter">Shor’s Algorithm</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/quantum/qubit.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="shor.html" title="Shor’s Algorithm"
             >next</a> |</li>
        <li class="right" >
          <a href="qft.html" title="QFT"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Qubit</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/qubit.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:46 GMT -->
</html>